import * as GC from "@grapecity-software/spread-sheets";
import "@grapecity-software/spread-sheets-shapes"
import "@grapecity-software/spread-sheets-charts"
import "@grapecity-software/spread-sheets-print"
import "@grapecity-software/spread-sheets-resources-zh"
import "@grapecity-software/spread-sheets-pdf"
import "@grapecity-software/spread-sheets-barcode"
import "@grapecity-software/spread-sheets-tablesheet"
import "@grapecity-software/spread-sheets-reportsheet-addon"
import "@grapecity-software/spread-sheets-slicers"
import "@grapecity-software/spread-sheets-pivot-addon"
import "@grapecity-software/spread-sheets-ganttsheet"
import "@grapecity-software/spread-sheets-datacharts-addon"
import "@grapecity-software/spread-sheets-io"
import "@grapecity-software/spread-excelio"
import "@grapecity-software/spread-sheets-languagepackages"
import "@grapecity-software/spread-sheets-designer-resources-cn"
import "@grapecity-software/spread-sheets-designer"

GC.Spread.Common.CultureManager.culture("zh-cn")

// GC.Spread.Sheets.LicenseKey = "表格控件部署授权"
// GC.Spread.Sheets.Designer.LicenseKey = "在线表格编辑器部署授权"

let config = GC.Spread.Sheets.Designer.DefaultConfig



designer = new GC.Spread.Sheets.Designer.Designer("designer-container", config)
spread = designer.getWorkbook()
sheet = spread.getActiveSheet()

// 这里的sheetcount不能设置太大，1个就已经很慢了，再多就直接卡死
let sheetCount = 1
document.getElementById("fetch").addEventListener("click", function () {
    console.time("从接口拉取数据")
    console.log("Sheet数量：", sheetCount)
    fetch('http://localhost:3000/large_data').then(response => {
        return response.json()
    }).then(res => {
        console.timeEnd("从接口拉取数据")
        console.log(res)
        console.log(`数据量：${Object.keys(res[0]).length}列，${res.length}行`)
        console.time("setArrayToSheets")
        spread.setSheetCount(sheetCount)
        spread.sheets.forEach(s => {
            s.setRowCount(res.length)
            s.setArray(0, 0, res)
        })
        console.timeEnd("setArrayToSheets")
    })
})

document.getElementById("btn").addEventListener("click", function () {
    console.time("reset sheets")
    spread.sheets.forEach(s => {
        s.reset()
    })
    console.timeEnd("reset sheets")
})